<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var articleTypeTreeGrid;
    $(function() {
        articleTypeTreeGrid = $('#articleTypeTreeGrid').treegrid({
            url : '${path}/articleType/treeGrid',
            idField : 'id',
            treeField : 'name',
            parentField : 'pid',
            fit : true,
            fitColumns : false,
            border : false,
            columns : [ [ 
                {
                width : '100',
                title : 'id',
                field : 'id',
                hidden:true
            },
                {
                width : '100',
                title : '名称',
                field : 'name'
            },
                {
                width : '100',
                title : '父类ID',
                field : 'pid',
                hidden:true
            },
                {
                width : '100',
                title : '排序',
                field : 'seq'
            } ,{
                width : '100',
                title : '图标',
                field : 'iconCls'
            } 
          ,{
                field : 'action',
                title : '操作',
                width : 200,
                formatter : function(value, row, index) {
                    var str = '';
                    str += $.formatString('<a href="javascript:void(0)" class="articleType-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editArticleTypeFun(\'{0}\');" >编辑</a>', row.id);
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="articleType-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteArticleTypeFun(\'{0}\');" >删除</a>', row.id);
                    return str;
                }
            } ] ],
            onLoadSuccess:function(row,data){
                $('.articleType-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.articleType-easyui-linkbutton-del').linkbutton({text:'删除'});
            },
            toolbar : '#articleTypeToolbar'
        });
    });
    
    function editArticleTypeFun(id) {
        if (id != undefined) {
            articleTypeTreeGrid.treegrid('select', id);
        }
        var node = articleTypeTreeGrid.treegrid('getSelected');
        if (node) {
            parent.$.modalDialog({
                title : '编辑',
                width : 500,
                height : 450,
                href : '${path}/articleType/editPage/' + node.id,
                buttons : [ {
                    text : '编辑',
                    handler : function() {
                        parent.$.modalDialog.openner_treeGrid = articleTypeTreeGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                        var f = parent.$.modalDialog.handler.find('#articleTypeEditForm');
                        f.submit();
                    }
                } ]
            });
        }
    }
    
    function deleteArticleTypeFun(id) {
        if (id != undefined) {
            articleTypeTreeGrid.treegrid('select', id);
        }
        var node = articleTypeTreeGrid.treegrid('getSelected');
        if (node) {
            parent.$.messager.confirm('询问', '您是否要删除'+node.name+'?', function(b) {
                if (b) {
                    progressLoad();
                    $.post('${path}/articleType/delete/'+node.id, {
                    }, function(result) {
                        if (result.success) {
                            parent.$.messager.alert('提示', result.msg, 'info');
                            articleTypeTreeGrid.treegrid('reload');
                        }else{
                            parent.$.messager.alert('提示', result.msg, 'info');
                        }
                        progressClose();
                    }, 'JSON');
                }
            });
        }
    }
    
    function addarticleTypeFun() {
        parent.$.modalDialog({
            title : '添加',
            width : 500,
            height : 400,
            href : '${path}/articleType/addPage',
            buttons : [ {
                text : '添加',
                handler : function() {
                    parent.$.modalDialog.openner_treeGrid = articleTypeTreeGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#articleTypeAddForm');
                    f.submit();
                }
            } ]
        });
    }

    function searchArticleTypeFun() {
        articleTypeTreeGrid.treegrid('load', $.serializeObject($('#searchArticleTypeForm')));
    }

    function cleanarticleTypeFun() {
        $('#searchArticleTypeForm input').val('');
        articleTypeTreeGrid.treegrid('load', {});
    }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false"  style="overflow: hidden;">
        <table id="articleTypeTreeGrid"></table>
    </div>
    <div id="articleTypeToolbar" style="display: none;">
        <form id="searchArticleTypeForm">
            <table>
                <tr>
                    <td>名称:</td>
                    <td><input name="name" placeholder="" class="easyui-text" style="width:200px"/>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="searchArticleTypeFun();">查询</a>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="cleanarticleTypeFun();">清空</a>
                    </td>
                </tr>
            </table>
        </form>
            <a onclick="addarticleTypeFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
    </div>
</div>